const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return `${[year, month, day].map(formatNumber).join('-')} ${[hour, minute, second].map(formatNumber).join(':')}`
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : `0${n}`
}
/** 判断为null或者空字符串,或者undefined */
const isNullOrEmpty=(data) => {
    if( typeof data == undefined || data==undefined ||data === null ||  data === ''){
        return true;
    }else{
        return false;
    }
}
/** 判断为null或者空字符串,或者undefined 并提醒信息*/
const notNullWarn=(data,msg) => {
    if( typeof data == undefined || data == undefined || data === null ||  data === ''){
        wx.showToast({title: msg,icon: 'none'});
        return true;
    }else{
        return false;
    }
}
/** containRoles roleCodes:需要校验的角色数组，personRoleList：当前人拥有的角色列表*/
const containRoles=(roleCodes,personRoleList) => {
  let hasRole = false;
  for(let i=0;i<roleCodes.length;i++){
    for(let j=0;j<personRoleList.length;j++){
      if(personRoleList[j] === roleCodes[i]){
        hasRole = true;
        break;
      }
    }    
  }
  return hasRole;
}
const fmtNumber=(data) => {
    var result = Number( data==null ? 0 : (data*1) );
    return result;
}
module.exports = {
  formatTime:formatTime,
  isNullOrEmpty:isNullOrEmpty,
  notNullWarn:notNullWarn,
  fmtNumber:fmtNumber,
  containRoles:containRoles
}
